package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.MesProduceOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * created by wangjunfu on 2022-03-30 15:28:42
 */
@Repository
public class MesProduceOrderDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(MesProduceOrderDao.class);

    public MesProduceOrder insert(final MesProduceOrder mesProduceOrder) {
        insert("MesProduceOrder.insert", mesProduceOrder);
        return mesProduceOrder;
    }

    public Boolean updateInfoById(final MesProduceOrder mesProduceOrder) {
        return update("MesProduceOrder.updateInfoById", mesProduceOrder) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("MesProduceOrder.updateInfoByQuery", query) > 0;
    }

    public MesProduceOrder selectById(final Integer id, final Integer entId) {
        Query query = Query.noPage();
        query.put("id", id);
        query.put("entId", entId);
        return queryForObject("MesProduceOrder.selectById", query);
    }

    public List<MesProduceOrder> selectByQuery(final Query query) {
        return queryForList("MesProduceOrder.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("MesProduceOrder.countByQuery", query);
    }

    public Boolean deleteById(final Integer id, final Integer entId) {
        MesProduceOrder mesProduceOrder = new MesProduceOrder();
        mesProduceOrder.setDeleteFlag(1);
        mesProduceOrder.setId(id);
        mesProduceOrder.setEntId(entId);

        return update("MesProduceOrder.updateInfoById", mesProduceOrder) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("MesProduceOrder.deleteById", query) > 0;
    }

    //以map的形式返回数据
    public List<Map<String, String>> getMapDataByQuery(final Query query, final String element) {
        return queryForList("MesProduceOrder." + element, query);
    }
}